package com.congwulin.wechat.controller;

import com.congwulin.wechat.entity.UserForWeChat;
import com.congwulin.wechat.repository.UserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//MongoDB调用实例
@Controller
@RequestMapping(value = "user")
public class UserController {
    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private UserRepository repository;

    @RequestMapping(value = "/getAll",method = RequestMethod.GET)
    public@ResponseBody
    List<UserForWeChat> getListByName(){
        return repository.findAll();
    }

    @RequestMapping(value = "/save",method = RequestMethod.POST)
    public@ResponseBody
    UserForWeChat save(@RequestBody UserForWeChat user){
        return repository.save(user);
    }

    @RequestMapping(value = "/getByName",method = RequestMethod.GET)
    public@ResponseBody
    UserForWeChat getByName(String name){
        return repository.findByName(name);
    }
}
